﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using QLBH.DAO;
using QLBH.DTO;
using System.Data;

namespace QLBH.BLO
{
    class BLO_TTTai
    {
        DAO_TTTai dao_tttai = new DAO_TTTai();
        public int Insert(TTTai tttai)
        {
            try
            {
                DataTable idmax = Connection_Sql.GetDatatable("select max(ma_TTTai) from Thongtintai", false);
                int map = 1;
                if (idmax.Rows[0][0].ToString() == "")
                {
                   tttai.Ma_tttai = map.ToString();
                }
                else
                {
                    tttai.Ma_tttai = (int.Parse(idmax.Rows[0][0].ToString()) + 1).ToString();
                }
                return dao_tttai.Insert(tttai);
            }
            catch (System.Exception ex)
            {
                throw new Exception("Lỗi BLO Insert TTTai: " + ex.Message);
            }
        }
    }
}
